package com.xuecheng.controller;

import com.xuecheng.service.CoursePublishService;
import com.xuecheng.vo.CoursePreviewVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * 课程发布 前端控制器
 */
@Slf4j
@RestController("CoursePublishController")
@Api(value = "课程发布", tags = "课程发布")
public class CoursePublishController {
	
	@Resource
	private CoursePublishService coursePublishService;
	
	@GetMapping("/coursepreview/{courseId}")
	@ApiOperation("预览课程")
	public ModelAndView preview(@PathVariable("courseId") Long id) {
		log.info("预览课程id：{}", id);
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("model", coursePublishService.getCoursePreviewInfo(id));
		modelAndView.setViewName("course_template");
		return modelAndView;
	}
	
	@GetMapping("/open/course/whole/{courseId}")
	@ApiOperation("课程公开查询")
	public CoursePreviewVO getPreviewInfo(@PathVariable("courseId") Long id) {
		log.info("课程公开查询id：{}", id);
		return coursePublishService.getCoursePreviewInfo(id);
	}
}
